<html>
<head><meta charset="utf-8"><title>How to acsess the name of a var when `Res::Local` · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20acsess.20the.20name.20of.20a.20var.20when.20.60Res.3A.3ALocal.60.html">How to acsess the name of a var when `Res::Local`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="226914316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20acsess%20the%20name%20of%20a%20var%20when%20%60Res%3A%3ALocal%60/near/226914316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Henry Boisdequin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20acsess.20the.20name.20of.20a.20var.20when.20.60Res.3A.3ALocal.60.html#226914316">(Feb 19 2021 at 02:55)</a>:</h4>
<p>In this case, I know that we are dealing with a local variable. Here is the check:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="n">Res</span>::<span class="n">Local</span><span class="p">(</span><span class="n">_</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">def</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">      </span><span class="nb">Some</span><span class="p">(</span><span class="fm">format!</span><span class="p">(</span><span class="s">"has type `{}`"</span><span class="p">,</span><span class="w"> </span><span class="n">callee_ty</span><span class="p">))</span><span class="w"></span>
<span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">      </span><span class="nb">Some</span><span class="p">(</span><span class="fm">format!</span><span class="p">(</span><span class="s">"`{}` defined here"</span><span class="p">,</span><span class="w"> </span><span class="n">callee_ty</span><span class="p">))</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Is there a way to access the name of the variable knowing that <code>def</code> refers to the path of the variable?</p>



<a name="226923003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20acsess%20the%20name%20of%20a%20var%20when%20%60Res%3A%3ALocal%60/near/226923003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20acsess.20the.20name.20of.20a.20var.20when.20.60Res.3A.3ALocal.60.html#226923003">(Feb 19 2021 at 05:45)</a>:</h4>
<p>Something in <code>rustc_resolve</code> <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/index.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/index.html</a>?</p>



<a name="226923440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20acsess%20the%20name%20of%20a%20var%20when%20%60Res%3A%3ALocal%60/near/226923440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20acsess.20the.20name.20of.20a.20var.20when.20.60Res.3A.3ALocal.60.html#226923440">(Feb 19 2021 at 05:55)</a>:</h4>
<p><span class="user-mention" data-user-id="383558">@Henry Boisdequin</span> the field you're ignoring is a HirId, which you can call tcx.hir().name() on: <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.name">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.name</a></p>



<a name="226925640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20acsess%20the%20name%20of%20a%20var%20when%20%60Res%3A%3ALocal%60/near/226925640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Henry Boisdequin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20acsess.20the.20name.20of.20a.20var.20when.20.60Res.3A.3ALocal.60.html#226925640">(Feb 19 2021 at 06:37)</a>:</h4>
<p>Thanks <span class="user-mention" data-user-id="232545">@Joshua Nelson</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>